@echo off
SET jsdocToolkitLoc=%~dp0

:findJsdocToolkitLoc
IF NOT EXIST "%jsdocToolkitLoc%jsrun.jar" (
	SET /P jsdocToolkitLoc=[Enter the full path to jsrun.jar including trailing backslash]
	GOTO findJsdocToolkitLoc
)


SET jsdocTemplateLoc=%jsdocToolkitLoc%templates\jsdoc
SET jsdocRunJsLoc=%jsdocToolkitLoc%app\run.js
SET jsdocJsRunLoc=%jsdocToolkitLoc%jsrun.jar

IF "%~1"=="" (
	SET /P src=[Enter the full path to your source folder without trailing backslash]
) ELSE (
	SET src=%~1
)
SET docsOutputDir=%src%\..\docs\jsdoc
SET jsdocLogOutputDir=%src%\..\logs
SET jsdocLogFileName=jsdoc-toolkit-error-log.txt
SET jsdocLogOutput=%jsdocLogOutputDir%\%jsdocLogFileName%

IF EXIST "%jsdocLogOutput%" (
DEL /F /Q "%jsdocLogOutput%"
)
IF EXIST "%docsOutputDir%" (
RMDIR /S /Q "%docsOutputDir%"
)
IF NOT EXIST "%jsdocLogOutputDir%" (
MKDIR "%jsdocLogOutputDir%"
)

java -jar "%jsdocJsRunLoc%" "%jsdocRunJsLoc%" -a -p -d="%docsOutputDir%" -o="%jsdocLogOutput%" -t="%jsdocTemplateLoc%" "%src%"

echo Errors, if any, have been logged to %jsdocLogOutput%
